<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="_fragments::header(~{::title})">
    <meta charset="UTF-8">
    <title th:text="${blog.title}+'_'+${blog.user.nickname}+'的博客'">博客详情</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.css">
    <link rel="stylesheet" href="../static/css/typo.css">
    <link rel="stylesheet" href="../static/css/animate.css">
    <link rel="stylesheet" href="../static/lib/prism/prism.css">
    <link rel="stylesheet" href="../static/lib/tocbot/tocbot.css">
    <link rel="stylesheet" href="../static/css/me.css">
    <link>
</head>
<body>
<!--导航栏-->
<nav th:replace="_fragments::menu(1)" class="ui  inverted attached segment m-padded-tb-mini m-shadow-small">
    <div class="ui container">
        <div class="ui inverted secondary stackable menu">
            <h2 class="ui teal header item ">Blog</h2>
            <a class="m-item item m-mobile-hide"><i class="home icon"></i>首页</a>
            <a class="m-item item m-mobile-hide"><i class="idea icon"></i>分类</a>
            <a class="m-item item m-mobile-hide"><i class="tags icon"></i>标签</a>
            <a class="m-item item m-mobile-hide"><i class="clone icon"></i>归档</a>
            <a class="m-item item m-mobile-hide"><i class="info icon"></i>我的</a>
            <div class="right m-item item m-mobile-hide">
                <div class="ui icon inverted transparent input  m-margin-tb-tiny">
                    <input type="text" placeholder="搜索">
                    <i class="search link icon"></i>
                </div>
            </div>
        </div>
    </div>
    <a href="#" class="ui menu toggle black icon button m-right-top m-mobile-show">
        <i class="sidebar icon"></i>
    </a>
</nav>

<!--中间部分-->
<div id="waypoint" class="m-container-small m-padded-tb-big animate__animated animate__fadeIn">
    <div class="ui container ">
        <!--header-->
        <div class="ui top attached segment">
            <div class="ui horizontal link list">
                <div class="item">
                    <img th:src="@{${blog.user.avatar}}" class="ui avatar image m-margin-bottom-tiny"
                         src="https://picsum.photos/id/1005/100/100" alt="头像">
                    <div class="content"><a th:text="${blog.user.nickname}" href="#"
                                            class="header m-margin-bottom-tiny">定春</a></div>
                </div>
                <div class="item">
                    <i class="calendar icon m-margin-bottom-mini"></i>
                    <span th:text="${blog.updateTime>blog.createTime}?
                    '已于 '+${#dates.format(blog.updateTime,'yyyy-MM-dd HH:mm:ss')}+' 修改':
                    '于 '+${#dates.format(blog.createTime,'yyyy-MM-dd HH:mm:ss')}+' 发布'">2021-08-15</span>
                </div>
                <div class="item">
                    <i class="eye icon m-margin-bottom-mini"></i><span th:text="${blog.views}">81203</span>
                </div>
            </div>
        </div>
        <!--图片-->
        <div class="ui attached segment">
            <img th:src="@{${blog.firstPicture}}" src="https://picsum.photos/id/1002/800/450" alt=""
                 class="ui fluid image rounded">
        </div>
        <!--主体内容-->
        <div class="ui  attached padded segment">
            <div class="ui right aligned basic segment">
                <div class="ui label basic orange" th:text="${blog.flag}">原创</div>
            </div>
            <!--文章标题-->
            <h2 class="ui center aligned header" th:text="${blog.title}">地方还是标点符号是否健康的室内空间</h2>
            <br>
            <!--文章内容  th:utext不转义html元素-->
            <div id="content" th:utext="${blog.content}"
                 class="typo typo-selection js-toc-content m-padded-lr-responsive m-padded-tb-large">
                <h2 id="assadas">放而威尔</h2>
                <pre><code class="language-css">p { color: red }</code></pre>
                <pre><code class="language-css">p { color: red }</code></pre>
                <h1 id="ads">1.但肌肤</h1>
                <p>eifw您的河北迁安副科级按时缴纳副刊上看了小抄吗·</p>
                <h2 id="ad2">鼎折覆餗</h2>
                <p>eifw您的河北迁安副科级按时缴纳副刊上看了小抄吗·</p>
                <p>eifw您的河北迁安副科级按时缴纳副刊上看了小抄吗·</p>
                <h3 id="ad3">h撒3</h3>
                <p>eifw您的河北迁安副科级按时缴纳副刊上看了小抄吗·</p>
                <p>eifw您的河北迁安副科级按时缴纳副刊上看了小抄吗·</p>
                <p>eifw您的河北迁安副科级按时缴纳副刊上看了小抄吗·</p>
                <p>eifw您的河北迁安副科级按时缴纳副刊上看了小抄吗·</p>
                <p>eifw您的河北迁安副科级按时缴纳副刊上看了小抄吗·</p>
                <p>eifw您的河北迁安副科级按时缴纳副刊上看了小抄吗·</p>
                <p>eifw您的河北迁安副科级按时缴纳副刊上看了小抄吗·</p>
                <h1 id="ad">1.但肌肤</h1>
                <p>eifw您的河北迁安副科级按时缴纳副刊上看了小抄吗·</p>
            </div>

            <!--标签-->
            <div class="m-padded-lr-responsive">
                <div class="ui basic teal left pointing label" th:each="tag:${blog.tags}" th:text="${tag.name}">Redis
                </div>
            </div>

            <!--赞赏-->
            <div class="ui center aligned basic segment" th:if="${blog.appreciation}">
                <button id="payButton" class="ui orange basic circular button">赞赏</button>
            </div>
            <!--隐藏的支付码-->
            <div class="ui payQ flowing popup transition hidden">
                <div class="ui orange basic label">
                    <!--字体尺寸继承父组件 images默认font-size:0 显示不了文字-->
                    <div class="ui images" style="font-size: inherit !important;">
                        <div class="image">
                            <img src="../static/images/wechat.jpg" th:src="@{/images/wechat.jpg}" alt=""
                                 class="ui rounded bordered image"
                                 style="width: 120px">
                            <div>支付宝</div>
                        </div>
                        <div class="image">
                            <img src="../static/images/wechat.jpg" th:src="@{/images/wechat.jpg}" alt=""
                                 class="ui rounded bordered image"
                                 style="width: 120px">
                            <div>微信</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!--转载声明-->
        <div class="ui attached positive message" th:if="${blog.shareStatement}">
            <!--博客信息-->
            <div class="ui middle aligned grid">
                <div class="eleven wide column">
                    <ui class="list">
                        <li>作者：<span th:text="${blog.user.nickname}">定春</span><a href="#" th:href="@{/about}"
                                                                                 target="_blank">（联系作者）</a></li>
                        <li>发表时间：<span
                                th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd HH:mm')}">2021-08-20 09:08</span>
                        </li>
                        <li>版权声明：自由转载-非商用-非衍生-保持署名（创意共享3.0许可证）</li>
                        <li>公众号转载：请在文末添加作者公众号二维码</li>
                    </ui>
                </div>
                <div class="five wide column">
                    <img src="../static/images/wechat.jpg" th:src="@{/images/wechat.jpg}" alt=""
                         class="ui right float rounded bordered image"
                         style="width: 110px">
                </div>
            </div>
        </div>
        <!--评论 th:if="${blog.commentabled}"-->
        <div id="comment-container" th:if="${blog.commentabled}" class="ui bottom attached segment">
            <!--留言区域列表-->
            <div th:fragment="commentList" class="ui teal segment">
                <div class="ui threaded comments" style="max-width: 100%;">
                    <h3 class="ui dividing header">评论</h3>
                    <div class="comment" th:each="comment:${comments}">
                        <a class="avatar">
                            <img src="https://picsum.photos/id/1005/100/100" th:src="@{${comment.avatar}}">
                        </a>
                        <div class="content">
                            <a class="author" th:text="${comment.nickname}">Matt</a>
                            <div class="ui mini basic teal left pointing label m-padded-mini"
                                 th:if="${comment.adminComment}">博主
                            </div>
                            <div class="metadata">
                                <span class="date" th:text="${#dates.format(comment.createTime,'yyyy-MM-dd HH:mm')}">今天下午 5:42</span>
                            </div>
                            <div class="text" th:text="${comment.content}">太赞了！</div>
                            <div class="actions">
                                <a class="reply" data-commentid="1" data-commentnickname="Matt"
                                   th:attr="data-commentid=${comment.id},data-commentnickname=${comment.nickname}"
                                   onclick="reply(this)">回复</a>
                            </div>
                        </div>
                        <div class="comments" th:if="${#arrays.length(comment.replyComments)}>0">
                            <div class="comment" th:each="reply : ${comment.replyComments}">
                                <a class="avatar">
                                    <img src="https://unsplash.it/100/100?image=1005" th:src="@{${reply.avatar}}">
                                </a>
                                <div class="content">
                                    <a class="author">
                                        <span th:text="${reply.nickname}">小红</span>&nbsp;
                                        <div class="ui mini basic teal left pointing label m-padded-mini"
                                             th:if="${reply.adminComment}">博主
                                        </div>
                                        <span th:text="|@ ${reply.parentComment.nickname}|" class="m-teal">@ 小白</span>
                                    </a>
                                    <div class="metadata">
                                        <span class="date"
                                              th:text="${#dates.format(reply.createTime,'yyyy-MM-dd HH:mm')}">Today at 5:42PM</span>
                                    </div>
                                    <div class="text" th:text="${reply.content}">
                                        How artistic!
                                    </div>
                                    <div class="actions">
                                        <a class="reply" data-commentid="1" data-commentnickname="Matt"
                                           th:attr="data-commentid=${reply.id},data-commentnickname=${reply.nickname}"
                                           onclick="reply(this)">回复</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
        <!--留言区域提交表单-->
        <div id="comment-form" th:if="${blog.commentabled}" class="ui form">
            <form class="ui reply form">
                <div class="ui error mini message"></div>
                <input type="hidden" name="blog.id" th:value="${blog.id}">
                <input type="hidden" name="parentComment.id" value="-1">
                <div class="required field">
                    <textarea name="content" placeholder="请输入评论信息..."></textarea>
                </div>
                <div class="fields">
                    <div class="required field m-mobile-wide  m-margin-bottom-small">
                        <div class="ui left icon input">
                            <i class="user icon"></i>
                            <input type="text" name="nickname" placeholder="姓名"
                                   th:value="${session.user}!=null ? ${session.user.nickname}">
                        </div>
                    </div>
                    <div class="required field m-mobile-wide m-margin-bottom-small">
                        <div class="ui left icon input">
                            <i class="mail icon"></i>
                            <input type="text" name="email" placeholder="邮箱"
                                   th:value="${session.user}!=null ? ${session.user.email}">
                        </div>
                    </div>
                    <div class="field m-margin-bottom-small  m-mobile-wide">
                        <button id="commentpost-btn" type="button" class="ui teal button m-mobile-wide">
                            <i class="edit icon"></i>发布
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<!--工具悬浮栏-->
<div id="toolbar" class="m-padded m-fixed m-right-bottom" style="display: none">
    <div class="ui vertical icon buttons ">
        <button type="button" class="ui toc teal button">目录</button>
        <a href="#comment-container" class="ui teal button">留言</a>
        <button class="ui wechat icon button"><i class="wechat icon"></i></button>
        <div id="toTop-button" class="ui icon button"><i class="chevron up icon"></i></div>
    </div>
</div>

<!--生成的目录-->
<div class="ui toc-container flowing popup transition hidden" style="width: 250px;">
    <ol class="js-toc"></ol>
</div>
<!--<div class="ui toc-container m-text" style="position:fixed;left: 0;top: 100px; width: 250px;">-->
<!--    <ol class="js-toc"></ol>-->
<!--</div>-->

<!--弹出的二维码-->
<div id="qrcode" class="ui wechat-qr flowing popup transition hidden " style="width: 130px !important;">
    <!--    <img src="./images/wechat.jpg" alt="" class="ui rounded image" style="width: 120px !important;">-->
</div>


<br>
<br>


<!--底部-->
<footer th:replace="_fragments::footer" class="ui inverted vertical segment m-padded-tb-massive">
    <div class="ui center aligned  container">
        <div class="ui inverted divided stackable grid">
            <div class="three wide column">
                <div class="ui inverted link list">
                    <div class="item">
                        <img src="../static/images/wechat.jpg" class="ui rounded image" alt="" style="width: 110px">
                    </div>
                </div>
            </div>
            <div class="three wide column">
                <h4 class="ui inverted header m-text-thin m-text-spaced ">最新博客</h4>
                <div class="ui inverted link list m-text-thin m-text-spaced m-opacity-mini">
                    <a href="#" class="item">用户故事 User story</a>
                    <a href="#" class="item">用户故事 User story</a>
                    <a href="#" class="item">用户故事 User story</a>
                </div>
            </div>
            <div class="three wide column">
                <h4 class="ui inverted header m-text-thin m-text-spaced ">联系我</h4>
                <div class="ui inverted link list m-text-thin m-text-spaced m-opacity-mini">
                    <a href="#" class="item m-text-lined">Email: xingzq.dc@foxmail.com</a>
                    <a href="#" class="item">QQ: 1961329303</a>
                </div>
            </div>
            <div class="seven wide column">
                <h4 class="ui inverted header m-text-thin m-text-spaced ">定春</h4>
                <p class="m-text-thin m-text-spaced m-opacity-mini">
                    这是我的个人博客，也是我第一个上线的项目，我未来职业规划是当一名Java开发工程师，并朝着架构师的目标努力前行！</p>
            </div>
        </div>
        <div class="ui inverted section divider"></div>
        <p class="m-text-thin m-text-spaced m-opacity-tiny">Copyright © 2021 - 2022 Dingchun Designed by Dingchun</p>
    </div>
</footer>


<!--/*/<th:block th:replace="_fragments :: script">/*/-->
<script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery.scrollto@2.1.2/jquery.scrollTo.min.js"></script>
<script src="../static/lib/prism/prism.js" th:src="@{}"></script>
<script src="../static/lib/tocbot/tocbot.min.js"></script>
<script src="../static/lib/qrcode/qrcode.min.js"></script>
<script src="../static/lib/waypoints/jquery.waypoints.min.js"></script>
<!--/*/</th:block>/*/-->


<script th:inline="javascript">
    /*初始化目录*/
    tocbot.init({
        // Where to render the table of contents.
        tocSelector: '.js-toc',
        // Where to grab the headings to build the table of contents.
        contentSelector: '.js-toc-content',
        // Which headings to grab inside of the contentSelector element.
        headingSelector: 'h1, h2, h3',
    });


    /*隐藏导航栏右上角图标（PC端时）*/
    $('.menu.toggle').click(function () {
        $('.m-item').toggleClass('m-mobile-hide');
    });

    /*赞赏按钮点击弹窗*/
    $('#payButton').popup({
        popup: $('.payQ.popup'),
        on: 'click',
        position: 'bottom center'
    });

    /*赞赏按钮点击弹窗*/
    $('.toc.button').popup({
        popup: $('.toc-container.popup'),
        on: 'click',
        position: 'left center'
    });

    /*鼠标放上去弹出二维码*/
    $('.wechat').popup({
        popup: $('.wechat-qr'),
        position: 'left center'
    });

    /*生成二维码 window.location.href*/
    var serurl = /*[[#{blog.serurl}]]*/"127.0.0.1:8080";
    var url = /*[[@{/blog/{id}(id=${blog.id})}]]*/"";
    var qrcode = new QRCode("qrcode", {
        text: serurl + url,
        width: 110,
        height: 110,
        colorDark: "#000000",
        colorLight: "#ffffff",
        correctLevel: QRCode.CorrectLevel.H
    });


    /*平滑移动*/
    $('#toTop-button').click(function () {
        $(window).scrollTo(0, 500);
    });

    /*滑到一定位置出现悬浮框*/
    var waypoint = new Waypoint({
        element: document.getElementById('waypoint'),
        handler: function (direction) {
            if (direction == 'down') {
                $('#toolbar').show(100);
            } else {
                $('#toolbar').hide(500);
            }
            console.log('Scrolled to waypoint!  ' + direction);
        }
    })

    //评论表单验证
    $('.ui.form').form({
        fields: {
            title: {
                identifier: 'content',
                rules: [{
                    type: 'empty',
                    prompt: '请输入评论内容'
                }]
            },
            content: {
                identifier: 'nickname',
                rules: [{
                    type: 'empty',
                    prompt: '请输入你的大名'
                }]
            },
            type: {
                identifier: 'email',
                rules: [{
                    type: 'email',
                    prompt: '请填写正确的邮箱地址'
                }]
            }
        }
    });

    // $(function(){
    //     if(navigator.userAgent.match(/mobile/i)) {
    //         console.log('mobile phone')
    //     }else {
    //         console.log('pc')
    //     }
    // });

    //加载评论列表数据
    $(function () {
        $("#comment-container").load(/*[[@{/comments/{id}(id=${blog.id})}]]*/"comments/6");
    });

    //点击留言表单提交按钮
    $('#commentpost-btn').click(function () {
        var boo = $('.ui.form').form('validate form');
        console.log(boo)
        console.log(boo[0])
        //前端表单验证（非空）
        if (boo[0]) {
            console.log('校验成功');
            postData();
        } else {
            console.log('校验失败');
        }

    });


    //留言表单提交事件 ajax局部刷新 提交表单数据自动封装成comment
    function postData() {
        $("#comment-container").load(/*[[@{/comments}]]*/"/comments", {
            "parentComment.id": $("[name='parentComment.id']").val(),
            "blog.id": $("[name='blog.id']").val(),
            "nickname": $("[name='nickname']").val(),
            "email": $("[name='email']").val(),
            "content": $("[name='content']").val()
        }, function (responseTxt, statusTxt, xhr) {
            $(window).scrollTo($('#comment-container'), 500);
            clearContent();
        });
    }

    //提交后重置留言表单内容
    function clearContent() {
        $("[name='content']").val('');
        $("[name='parentComment.id']").val(-1);
        $("[name='content']").attr("placeholder", "请输入评论信息...");
    }

    //点击回复 跳到表单处并赋值
    function reply(obj) {
        var commentId = $(obj).data('commentid');
        var commentNickname = $(obj).data('commentnickname');
        $("[name='content']").attr("placeholder", "@" + commentNickname).focus();
        $("[name='parentComment.id']").val(commentId);
        $(window).scrollTo($('#comment-form'), 500);
    }


</script>

</body>
</html>